﻿//  Copyright (c) 2010 Ray Liang (http://www.dotnetage.com)
//  Dual licensed under the MIT and GPL licenses:
//  http://www.opensource.org/licenses/mit-license.php
//  http://www.gnu.org/licenses/gpl.html

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DNA.Mvc.jQuery;
using System.Text;

namespace DNA.Mvc.jQuery
{
    public class TitleViewBuilder : ViewComponentBuilder<TitleView, TitleViewBuilder>
    {
        public TitleViewBuilder(TitleView component, ViewContext context, IViewDataContainer container) : base(component, context, container) { }

        public TitleViewBuilder Template(Action value)
        {
            this.Component.Template.Content = value;
            return this;
        }
        
        public TitleViewBuilder Template(Func<object, object> value)
        {
            this.Component.Template.InlineContent = value;
            return this;
        }
    }

    public class TitleViewFactory : ViewComponentBuilderFactory<TitleView>
    {
        public TitleViewFactory(IComponentItemContainer<TitleView> container, ViewContext viewContext, IViewDataContainer viewContainer) : base(container, viewContext, viewContainer) { }

        public TitleViewBuilder Add(string title)
        {
            var item = new TitleView() { Title = title };
            Container.Items.Add(item);
            Container.OnItemAdded(item);
            return new TitleViewBuilder(item, this.ViewContext,this.ViewDataContainer);
        }
    }
}
